import {onMounted, onUnmounted, ref} from "vue";

function useWindowResize(w = 0, h = 0, resize?: Function) {
    const width = ref(0);
    const height = ref(0);

    function onResize() {
        width.value = window.innerWidth - w;
        height.value = window.innerHeight - h;
        resize && resize()
    }

    onMounted(() => {
        window.addEventListener("resize", onResize);
        onResize();
    });

    onUnmounted(() => {
        window.removeEventListener("resize", onResize);
    });

    return {
        width,
        height
    };
}

export default useWindowResize;
